package com.lzh.media.controller;

import com.lzh.common.pojo.Result;
import com.lzh.media.entity.WmUser;
import com.lzh.media.service.WmUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author lizuhu
 * @date 2021/6/28 23:28
 */
@RestController
@RequestMapping("/wmUser")
public class LoginController {

    @Autowired
    private WmUserService wmUserService;

    /***
     * 登录
     */
    @ApiOperation(value = "自媒体用户登录")
    @PostMapping("/login")
    public Result login(@RequestBody WmUser wmUser){

        if (StringUtils.isEmpty(wmUser) || StringUtils.isEmpty(wmUser.getName()) || StringUtils.isEmpty(wmUser.getPassword())) {
            return Result.errorMessage("用户名或密码不能为空！");
        }
        Map<String,Object> resultMap = wmUserService.login(wmUser);
        if (resultMap != null) {
        return Result.ok(resultMap);
        } else {
            return Result.error("登录失败！");
        }
    }

}
